package cn.zyq.ykb.controller.mgt.user;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.user.UserPromotion;
import cn.zyq.ykb.service.user.UserPromotionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户-推广Controller
 *
 * @author SystemAuth
 * @date 2023-05-23
 */

@RestController(value = "MgtUserPromotionController")
@RequestMapping("/mgt/userPromotion")
@Api(tags = "用户-推广接口")
public class UserPromotionController extends BaseController {

    @Autowired
    private UserPromotionService userPromotionService;

    /**
     * 查询用户-推广列表
     */
    @ApiOperation(value = "列表", response = UserPromotion.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.userPromotionService.selectUserPromotionList(pageParam);
    }

     /**
      * 导出用户-推广列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "用户-推广" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, UserPromotion userPromotion) {
         List<UserPromotion> list = userPromotionService.selectUserPromotionList(userPromotion);
         ExcelUtil<UserPromotion> util = new ExcelUtil<UserPromotion>(UserPromotion. class);
         util.exportExcel(response, list, "用户-推广数据");
     }

    /**
     * 获取用户-推广详细信息
     */
    @ApiOperation(value = "详情", response = UserPromotion.class)
    @GetMapping(value = "/{userPromotionID}")
    public Object getInfo(@PathVariable("userPromotionID") Integer userPromotionID) {
        return this.userPromotionService.selectUserPromotionByUserPromotionID(userPromotionID);
    }
    /**
     * 获取用户-推广详细信息
     */
    @ApiOperation(value = "详情", response = UserPromotion.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.userPromotionService.selectUserPromotionByServiceID(serviceID);
    }

    /**
     * 新增用户-推广
     */
    @ApiOperation(value = "新增")
    @Log(title = "用户-推广", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody UserPromotion userPromotion) {
        return this.userPromotionService.insertUserPromotion(userPromotion);
    }

    /**
     * 修改用户-推广
     */
    @ApiOperation(value = "编辑")
    @Log(title = "用户-推广", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody UserPromotion userPromotion) {
        return this.userPromotionService.updateUserPromotion(userPromotion);
    }

    /**
     * 删除用户-推广
     */
    @ApiOperation(value = "删除")
    @Log(title = "用户-推广", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userPromotionIDs}")
    public Object remove(@PathVariable Integer[] userPromotionIDs) {
        return this.userPromotionService.deleteUserPromotionByUserPromotionIDs(userPromotionIDs);
    }
}
